﻿using System;
using TLV.RestrictionsValidation.analysis;
using TLV.RestrictionsValidation.node;

namespace TLV.RestrictionsValidation
{
    class ASTPrinter : DepthFirstAdapter
    {
        int indent;

        private void printIndent()
        {
            Console.Write("".PadLeft(indent, '\t'));
        }

        private void printNode(Node node)
        {
            printIndent();

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(node.GetType().ToString().Replace("SimpleCalc.node.", ""));

            if (node is ANumberExp)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("  " + node.ToString());
            }
            else if (node is AStringExp)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("  " + ((AStringExp)node).GetString());
            }
            else
                Console.WriteLine();
        }

        public override void DefaultIn(Node node)
        {
            printNode(node);
            indent++;
        }

        public override void DefaultOut(Node node)
        {
            indent--;
        }
    }
}